class Solution {
public:
    vector<int> maxSubsequence(vector<int>& nums, int k) {
        vector<int> arr = nums;
        sort(nums.begin(), nums.end());
        vector<int> res;
        unordered_map<int, int> mp;
        for (int i = nums.size() - 1; k > 0; i --, k -- ) 
            mp[nums[i]] ++ ;
        for (auto & n : arr) {
            if (mp[n] != 0) {
                mp[n] -- ;
                res.push_back(n);
            }
        }
        return res;
    }
};
